﻿
using Microsoft.JSInterop;

namespace BlazorApp.Services
{
    public class JsService : IAsyncDisposable
    {
        private readonly string _name;

        public JsService(string name)
        {
            _name = name;
        }

        // 这个方法可以被 JS 调用
        [JSInvokable]
        public async Task<string> GreetAsync(string message)
        {
            await Task.Delay(100); // 模拟异步操作
            return $"[{_name}] says: {message}";
        }

        // 实现 IAsyncDisposable 用于清理
        public ValueTask DisposeAsync()
        {
            // 执行清理逻辑
            Console.WriteLine($"{_name} is being disposed.");
            return ValueTask.CompletedTask;
        }
    }
}
